import random

import pygame

from constants import SCREEN_WIDTH, SCREEN_HEIGHT


# 普通敌机类
class OrdinaryEnemy(pygame.sprite.Sprite):
    def __init__(self, image):
        super().__init__()
        self.image = image
        self.rect = self.image.get_rect(x=random.randint(0, SCREEN_WIDTH-40), y=-40)
        self.speed = 2
        self.health = 10
        self.score = 1

    def update(self, *args, **kwargs):
        self.rect.y += self.speed
        if self.rect.top > SCREEN_HEIGHT:
            self.kill()

# 快速敌机类
class FastEnemy(pygame.sprite.Sprite):
    def __init__(self, image):
        super().__init__()
        self.image = image
        self.rect = self.image.get_rect(x=random.randint(0, SCREEN_WIDTH-40), y=-40)
        self.speed = 5
        self.health = 10
        self.score = 2

    def update(self, *args, **kwargs):
        self.rect.y += self.speed
        if self.rect.top > SCREEN_HEIGHT:
            self.kill()

# 重型敌机类
class HeavyEnemy(pygame.sprite.Sprite):
    def __init__(self, image):
        super().__init__()
        self.image = image
        self.rect = self.image.get_rect(x=random.randint(0, SCREEN_WIDTH-40), y=-40)
        self.speed = 2
        self.health = 50
        self.score = 5

    def update(self, *args, **kwargs):
        self.rect.y += self.speed
        if self.rect.top > SCREEN_HEIGHT:
            self.kill()

# 精英敌机类
class EliteEnemy(pygame.sprite.Sprite):
    def __init__(self, image):
        super().__init__()
        self.image = image
        self.rect = self.image.get_rect(x=random.randint(0, SCREEN_WIDTH-40), y=-40)
        self.speed = 5
        self.health = 50
        self.score = 10

    def update(self, *args, **kwargs):
        self.rect.y += self.speed
        if self.rect.top > SCREEN_HEIGHT:
            self.kill()

# 超级敌机类
class SuperEnemy(pygame.sprite.Sprite):
    def __init__(self, image):
        super().__init__()
        self.image = image
        self.rect = self.image.get_rect(x=random.randint(0, SCREEN_WIDTH-40), y=-40)
        self.speed = 3
        self.health = 100
        self.score = 20

    def update(self, *args, **kwargs):
        self.rect.y += self.speed
        if self.rect.top > SCREEN_HEIGHT:
            self.kill()

# Boss敌机类
class BossEnemy(pygame.sprite.Sprite):
    def __init__(self, image):
        super().__init__()
        self.image = image
        self.rect = self.image.get_rect(x=SCREEN_WIDTH//2, y=0)
        self.speed = 2
        self.health = 500
        self.direction = 0
        self.score = 100

    def update(self, *args, **kwargs):
        if self.direction == 0:
            self.rect.x += self.speed
            if self.rect.x >= SCREEN_WIDTH:
                self.direction = 1
        else:
            self.rect.x -= self.speed
            if self.rect.x <= 0:
                self.direction = 0